package com.nd.service;

import com.nd.dao.StatMapper;
import com.nd.pojo.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author : PengFei Zhang
 * @Data :2021/6/6  20:33
 * @Description :
 */
// 统计报表  zpf
@Service
public class StatFormServiceImpl implements StatFormService {

    @Autowired
    StatMapper orderMapper;

    //用户统计
    @Override
    public StatUserVo selectStatUser() {
        List<StatisticsUserVo> statisticsUserVos = orderMapper.getUserstat();
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");
        StatUserVo statUserVo = new StatUserVo();
        statUserVo.setColumns(columns);
        statUserVo.setRows(statisticsUserVos);
        return statUserVo;
    }

    //订单统计
    @Override
    public StatOrderVO statOrder() {
        StatOrderVO statUseVO = new StatOrderVO();
        List<String> columns = new ArrayList<>();
        columns.add("day");//日期 yyyy-MM-dd
        columns.add("orders");//订单数
        columns.add("customers");//下单用户数
        columns.add("amount");//下单货品总额
        columns.add("pcr");//客单价 = amount / customers
        statUseVO.setColumns(columns);
        List<Map> rows = orderMapper.statOrder();
        statUseVO.setRows(rows);

        return statUseVO;
    }

    //商品统计
    @Override
    public StatGoodsVo selectStatGoods() {
        List<StatisticsGoodsVo> statisticsGoodsVos = orderMapper.getGoodsstat();
        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        StatGoodsVo statGoodsVo = new StatGoodsVo();
        statGoodsVo.setColumns(columns);
        statGoodsVo.setRows(statisticsGoodsVos);
        return statGoodsVo;

    }


}
